package com.wms.wms.service;

import com.wms.wms.entity.OutStock;
import com.wms.wms.entity.Product;
import com.wms.wms.mapper.OutStockMapper;

import com.wms.wms.mapper.product.ProductMapper;
import com.wms.wms.mapper.product.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

@Service
public class OutStockService{
    @Autowired
    OutStockMapper outStockMapper;
    @Autowired
    ProductMapper productMapper;
    public int selectById(String id){
        return outStockMapper.selectById(id).getNum();
    }
    public int salesCountId(String id,Date b, Date e,int des){
        if(id.compareTo("000000") != 0) {
            return outStockMapper.queryCountByParam(id, b, e, des);
        }
        else return outStockMapper.queryCountByDate(b,e,des);
    }

    public int salesCountType(String typeId,Date b, Date e,int des) {
        List<Product> idList = productMapper.queryIdByType(typeId);
        int count = 0;
        for(Product id:idList){
            count += outStockMapper.queryCountByParam(id.getId(),b,e,des);
        }
        return count;
    }


    public double salesTotalId(String id,Date b,Date e){
        if(id.compareTo("000000") != 0){
            return outStockMapper.queryTotalById(id,b,e);
        }
        else return outStockMapper.queryTotalByDate(b,e);
    }

    public int salesTotalType(String typeId,Date b, Date e) {
        List<Product> idList = productMapper.queryIdByType(typeId);
        int count = 0;
        for(Product id:idList){
            count += outStockMapper.queryTotalById(id.getId(),b,e);
        }
        return count;
    }


    public ArrayList<OutStock> queryByIdAndDate(String id, Date bDate, Date eDate,int des){
        return outStockMapper.queryByIdAndDate(id,bDate,eDate,des);
    }

    public ArrayList<OutStock> queryByDate(String id, Date bDate, Date eDate,int des){
        return outStockMapper.queryByDate(id,bDate,eDate,des);
    }

    public ArrayList<OutStock> queryByTypeAndDate(String id, Date bDate, Date eDate,int des){
        List<Product> idList = productMapper.queryIdByType(id);
        ArrayList<OutStock> outStockList = new ArrayList<>();
        for(Product i:idList){
            outStockList.addAll(outStockMapper.queryByIdAndDate(i.getId(),bDate,eDate,des));
        }
        return outStockList;
    }
}
